package com.woniu.inlet.web;

import com.woniu.outlet.po.CompanyVipApplication;
import com.woniu.service.ICompanyVipApplicationService;
import com.woniu.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//这是一个处理申请客户vip的类
@RestController
@RequestMapping("/cli")
@Api(tags = "处理申请客户vip的类")
public class CompanyVipApplicationController {

    @Autowired
    private ICompanyVipApplicationService companyVipApplicationService;

    //客户经理提出将某个客户申请为VIP，然后需要营销经理来审批、审批通过了，就给客户发一条消息！！
    @ApiOperation(value = "applicationvip",notes = "客户经理提出将某个客户申请为VIP，" +
            "然后需要营销经理来审批、审批通过了，就给客户发一条消息！！")
    @PostMapping("/applicationvip")
    @PreAuthorize("hasRole('client')")
    public ResponseResult<String> applicationvip(@RequestBody CompanyVipApplication companyVipApplication){
        int applicationvip = companyVipApplicationService.applicationvip(companyVipApplication);
        return new ResponseResult<>("已经发出申请，请耐心等待！！",200);
    }

    //营销经理可以查看所有没有处理的申请
    @ApiOperation(value = "findAllCompanyVipApplication",notes = "营销经理可以查看所有没有处理的申请")
    @GetMapping("/findAllCompanyVipApplication")
    @PreAuthorize("hasRole('market')")
    public ResponseResult<List<CompanyVipApplication>> findAllCompanyVipApplication(){
        List<CompanyVipApplication> allCompanyVipApplication = companyVipApplicationService.findAllCompanyVipApplication();
        return new ResponseResult<>(allCompanyVipApplication,200);
    }

    //营销经理同意此客户成为vip客户
    @ApiImplicitParams({
            @ApiImplicitParam(value = "客户的id", name = "companyid", required = true,paramType = "query",dataType = "Integer"),
            @ApiImplicitParam(value = "申请表的id", name = "companyvipapplicationId", required = true,paramType = "query",dataType = "Integer")
    })
    @ApiOperation(value = "agreevipapplication",notes = "营销经理同意此客户成为vip客户")
    @GetMapping("/agreevipapplication")
    @PreAuthorize("hasRole('market')")
    public ResponseResult<String> agreevipapplication(Integer companyid,Integer companyvipapplicationId){
        int agreevipapplication = companyVipApplicationService.agreevipapplication(companyid, companyvipapplicationId);
        return new ResponseResult<>("申请vip成功！！",200);
    }


    //营销经理拒绝此客户成为vip客户
    @ApiImplicitParams({
            @ApiImplicitParam(value = "申请表的id", name = "companyvipapplicationId", required = true
            ,paramType = "query",dataType = "Integer")
    })
    @ApiOperation(value = "confusevipapplication",notes = "营销经理拒绝此客户成为vip客户")
    @GetMapping("/confusevipapplication")
    @PreAuthorize("hasRole('market')")
    public ResponseResult<String> confusevipapplication(Integer companyvipapplicationId){
        int confusevipapplication = companyVipApplicationService.confusevipapplication(companyvipapplicationId);
        return new ResponseResult<>("经理拒绝了你的申请！！",200);
    }


}
